﻿$(document).ready(function () {
    $("#City").bind("change", function () { getSelectItem($("#City").val(), $("#Town")) });
    $("#Town").bind("change", function () { getAreaValue($(this).val()) });
});


function getSelectItem(val, obj) {
    obj.find("option").remove();
    $.ajax({
        url: '/Area/selecttown/' + val,
        type: 'POST',
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        success: function (json) {
            if (json) {
                $.each(json.Towns, function (i, item) {
                    obj.append("<option value=" + item.Value + ">" + item.Text + "</option>");
                });
            }
        },
        error: function () {
        }
    });
    //            $.getJSON('/area/selecttown/' + val, function (json) {
    //                alert(json.Towns);
    //                $.each(json.Towns, function (i, item) {
    //                    obj.append("<option value=" + item.Value + ">" + item.Text + "</option>");
    //                });
    //            });
}

function getAreaValue(val) {
    $("#Area").val(val);
}      
